﻿using Autofac;
using IOCDemo.Interfaces;
using IOCDemo.Services;

namespace IOCDemo.Containers
{
    public class AutofacIOCContainer : IIOCContainer
    {
        private readonly IContainer container;
        private readonly ContainerBuilder containerBuilder = new ContainerBuilder();

        public AutofacIOCContainer()
        {
            containerBuilder.RegisterType<ConsoleLoggingService>().As<ILoggingService>();
            containerBuilder.RegisterType<XmlSettingsService>().As<ISettingsService>();
            containerBuilder.RegisterType<InProcCacheService>().As<ICacheService>();
            containerBuilder.RegisterType<MockAuditService>().As<IAuditService>();
            containerBuilder.RegisterType<MockAccountService>().As<IAccountService>();
            containerBuilder.RegisterType<MockUserService>().As<IUserService>();
            containerBuilder.RegisterType<BankingService>().As<IBankingService>();
            
            container = containerBuilder.Build();
        }

        #region Implementation of IIOCContainer

        public T Resolve<T>()
        {
            return container.Resolve<T>();
        }

        #endregion
    }
}